package com.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.bean.ClientBean;
import com.project.service.IClientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("client")
@Api(tags = "客户控制器")
public class ClientController {
    @Autowired
    private IClientService service;

    @RequiresPermissions("data:client")
    @RequestMapping("cutByItem")
    @ApiOperation(value = "客户分页", notes = "分页展示客户")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "pageNO", value = "页码", required = true),
            @ApiImplicitParam(name = "cName", value = "客户名称"),
            @ApiImplicitParam(name = "cRange", value = "客户经营范围")
    })
    public IPage<ClientBean> cutByItem(Integer pageNO, String cName, String cRange) {
        return service.cutByItem(pageNO, cName, cRange);
    }

    @RequiresPermissions("data:client")
    @RequestMapping("findByClientId")
    @ApiOperation(value = "根据客户id查询客户", notes = "根据客户id查询客户")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "clientId", value = "客户id", required = true),
    }
    )
    public ClientBean findByClientId(Integer clientId) {
        return service.findByClientId(clientId);
    }

    @RequiresPermissions("data:client")
    @RequestMapping("updateClient")
    @ApiOperation(value = "根据客户id修改客户负责人和负责人电话", notes = "根据客户id修改客户负责人和负责人电话")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "clientId", value = "客户id", required = true),
            @ApiImplicitParam(name = "cLeader", value = "客户负责人"),
            @ApiImplicitParam(name = "cLeader", value = "客户负责人电话"),
    }
    )
    public String updateClient(Integer clientId, String cLeader, String cLeaderPhone, String cRange) {
        service.updateClient(clientId, cLeader, cLeaderPhone, cRange);
        return "ok";
    }

    @RequiresPermissions("data:client")
    @RequestMapping("addClient")
    @ApiOperation(value = "添加客户", notes = "添加客户")
    public String addClient(ClientBean client) {
        service.addClient(client);
        return "ok";
    }

    @RequiresPermissions("data:client")
    @RequestMapping("findAllClient")
    @ApiOperation(value = "查询所有客户", notes = "查询所有客户")
    public List<ClientBean> findAllClient() {
        return service.findAllClient();
    }
}
